<HEAD> <TITLE> for loops </TITLE> </HEAD> <BODY BACKGROUND="http://www.imaginary.com/LPMud/Graphics/RecycledPaper.jpg" TEXT=#000000 ALINK=#FFFF00 VLINK=#550000 LINK=#000099> <center> <H1> for loops </H1> </center>
<p>
The for loop is the most general loop construct; <A HREF=http://www.imaginary.com/~beek/mudos/lpc/while.html>  while </A> and <A HREF=http://www.imaginary.com/~beek/mudos/lpc/do_while.html>  do while </A> loops
are also available, as well as <A HREF=http://www.imaginary.com/~beek/mudos/lpc/foreach.html>  foreach </A> loops.
<p>
The LPC for loop is very similar to that provided by C.  Syntax is as
follows:
<p>
<pre>
for (expression0; expression1; expression2) {
    statements;
    ...
}
</pre>
<p>
or
<p>
<pre>
for (expression0; expression1; expression2)
     statement;
</pre>
<p>
expression0 may also be of the form &#60;type&#62; name = ...; in that case
a new variable is declared.  Currently, the variable is in scope after the
loop, however this may change in the future.
<p>
expression0 is evaluated once prior to the execution of the loop.  expression1
is evaluated at the beginning of each iteration of the loop.  If expression1
evaluates to zero, then the loop terminates.  expression2 is evaluated at
the end of each loop iteration, just before expression1 is evaluated again.
<p>
<A HREF=http://www.imaginary.com/~beek/mudos/lpc/break.html>  break </A> can be used to exit of for loop prematurely, and <A HREF=http://www.imaginary.com/~beek/mudos/lpc/continue.html>  continue </A> can be
used to immediated evaluate expression2 and go back to the top of the loop.
<p>
See also the summary of <A HREF=http://www.imaginary.com/~beek/mudos/lpc/loops.html>  loops </A>.
<p>
<HR> <ADDRESS> <A HREF=http://wagner.princeton.edu/~tim>  Tim Hollebeek </A> <p> <A HREF="http://www.imaginary.com/~beek/">  Beek </A>@ZorkMUD, Lima Bean, IdeaExchange, TMI-2, and elsewhere </ADDRESS>
